package main

import (
	"log"

	"bbs/pkg/config"
	"bbs/pkg/handler"
	"bbs/pkg/model/session"
	"bbs/pkg/repository/mysql"
	"bbs/pkg/server"
)

func init() {
	if err := config.ParseConfiguration(); err != nil {
		log.Println("parse configuration failed")
		return
	}
}

func main() {
	// init database
	if err := mysql.InitDatabase(); err != nil {
		log.Println("init database failed: ", err)
		return
	}

	// initialize session
	if err := session.InitSessionsRedisStore(); err != nil {
		log.Println("initialize session failed, ", err)
		return
	}

	// setup apis
	router := handler.NewHandler()

	// start server
	server.Run(router)
}
